跳到主要内容

Use in the official OpenAI library.

This section provides the latest method for calling the OpenAI package.

from openai import OpenAI

client = OpenAI(
# Replace this with the key you obtained from aihubmix api keys
api_key="sk-xxx",
# Replace the official API endpoint with aihubmix's entry address
base_url="https://aihubmix.com/v1"
)

chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Say this is a test",
}
],
model="gpt-3.5-turbo",
)

print(chat_completion)

Other methods are the same as the official ones, just change the URL and key to use ours; for the specific API calling method, please refer to the official documentation.